/*
 * 创建日期 2009-3-17
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.cpp.web.tag;

import javax.servlet.jsp.JspException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import  org.fantasy.cpp.core.bean.ContextEntry;
import  org.fantasy.cpp.core.bean.ParamContext;
import  org.fantasy.cpp.core.tag.AbstractTag;

/**
 * 参数标签
 * @author: 王文成
 * @version: 1.0
 * @since 2009-3-17
 */
public class ParamTag extends AbstractTag {

    private static final Log log = LogFactory.getLog(ParamTag.class);

    public ParamTag() {
        log.debug(">>>>>>>>>>>>>>>>>>> New ParamTag instance!");
    }

    @Override
    protected void init() {
        pageContext.setAttribute(ContextEntry.CONTEXT_ENTRY, new ContextEntry());
    }

    public void setName(String name) {
        getContextEntry().setName(name);
    }

    public void setValue(String value) {
        getContextEntry().setValue(value);
    }

    @Override
    public int doStartTag() throws JspException {
        ParamContext param = getParamContext();
        ContextEntry entry = getContextEntry();
        param.set(entry.getName(), entry.getValue());
        return EVAL_PAGE;
    }

    private ParamContext getParamContext() {
        return (ParamContext) pageContext.getAttribute(ParamContext.PARAM_CONTEXT);
    }

    public ContextEntry getContextEntry() {
        return (ContextEntry) pageContext.getAttribute(ContextEntry.CONTEXT_ENTRY);
    }
}